package com.example.tsproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tsproject.entity.QuestionAndAssignment;
import com.example.tsproject.entity.QuestionDetails;
import com.example.tsproject.entity.Questions;
import com.example.tsproject.service.QuestionsService;
import com.example.tsproject.mapper.QuestionsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionsServiceImpl extends ServiceImpl<QuestionsMapper, Questions>
    implements QuestionsService {

    @Autowired
    private QuestionsMapper questionsMapper;

    @Override
    public List<Questions> generateQuestions(List<Integer> chapterRange, String quantity) {
        int singleChoiceLimit, tianKongTiLimit, trueFalseLimit;

        switch (quantity.toLowerCase()) {
            case "small":
                singleChoiceLimit = 3;
                tianKongTiLimit = 3;
                trueFalseLimit = 4;
                break;
            case "medium":
                singleChoiceLimit = 5;
                tianKongTiLimit = 5;
                trueFalseLimit = 10;
                break;
            case "large":
                singleChoiceLimit = 10;
                tianKongTiLimit = 10;
                trueFalseLimit = 10;
                break;
            default:
                throw new IllegalArgumentException("Invalid quantity type");
        }

        return questionsMapper.selectQuestionsByTypeAndChapter(chapterRange, singleChoiceLimit, tianKongTiLimit, trueFalseLimit);
    }
    @Override
    public List<Questions> getQuestionsByAssignmentId(Integer assignmentId) {
        return questionsMapper.selectQuestionsByAssignmentId(assignmentId);
    }
    @Override
    public List<QuestionDetails> getDetailedQuestionsByAssignmentIdAndStudentId(Integer assignmentId, String studentId) {
        System.out.println(assignmentId);
        System.out.println(studentId);
        System.out.println("AAAAAAAAAAA");
        return questionsMapper.selectDetailedQuestionsByAssignmentIdAndStudentId(assignmentId, studentId);
    }

    @Override
    public QuestionAndAssignment getQuestionByAssignmentQuestionId(Integer assignmentQuestionId,Integer assignmentId) {
        return questionsMapper.getQuestionByAssignmentQuestionId(assignmentQuestionId,assignmentId);
    }
}
